package com.zx.sa.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mcp")
public class McpClientController {

    private final ChatClient chatClient;

    public McpClientController(@Qualifier("ollamaChatModel") ChatModel chatModel, ToolCallbackProvider weatherTools) {
        this.chatClient = ChatClient.builder(chatModel)
                .defaultTools(weatherTools)
                .build();
    }


    @RequestMapping("/chat")
    public String chat(@RequestParam(value = "msg", defaultValue = "今天天气如何？") String msg) {
        String response = chatClient
                .prompt(msg)
                .call()
                .content();
        return response;
    }
}
